package messagepasser;


/**
 * 
 * @author Rishit Shroff(rshroff)
 * @author Huimin Yang(huiminy)
 * @description Contains the description of the Logical Clock Class 
 */

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class Logical extends ClockService implements Serializable, Cloneable{
	private int time;

	public Logical() {
		super();
		clockType = "Logical";
		time = 0;
	}
	
	public void doService() {
		this.time++;
		System.out.println("clock increased to " + time);
	}
	
	public int getTime() {
		return time;
	}
	
	// change the current clock to sync up with the received clock
	public void syncClock(List<String> nodeNames,ClockService clock) {
		int newTime = ((Logical)clock).getTime();
		if (newTime > time) {
			time = newTime;
		}
	}
	
	public String toString() {
	    return Integer.toString(time); 
	}
	
	public void initialize(List<String> nodeNames, String myName) {
		
	}
	public Object clone () {
        // The cast in the line below throws an exception!
        //
        Logical newObject = new Logical();
        newObject.time = this.time;
        return newObject;
    }
	
}
